package com.wang.lottery.infrastucture.mapper;

import cn.bugstack.middleware.db.router.annotation.DBRouter;
import cn.bugstack.middleware.db.router.annotation.DBRouterStrategy;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wang.lottery.domain.activity.model.po.UserStrategyExport;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * @author wjh
 * @create 2023-11-07 18:50
 * 用户策略计算结果表Mapper
 */
@Mapper
@DBRouterStrategy(splitTable = true)
public interface UserStrategyExportMapper extends BaseMapper<UserStrategyExport> {
    /**
     * 新增数据，按照uId进行哈希散列，然后分库分表
     *
     * @param userStrategyExport 用户策略
     * @return
     */
    @DBRouter(key = "uId")
    int insert(UserStrategyExport userStrategyExport);

    /**
     * 查询数据
     * @param uId 用户id
     * @return 用户策略
     */
    @DBRouter
    UserStrategyExport queryUserStrategyExportByUId(String uId);

    /**
     * 更新发送MQ状态
     * @param userStrategyExport 发送消息
     */
    @DBRouter
    void updateInvoiceMqState(UserStrategyExport userStrategyExport);

    /**
     * 扫描MQ发送失败的单子和mq状态为0且创建时间已经超过30分钟的单子
     * @return
     */
    List<UserStrategyExport> scanInvoiceMqState();
}
